/**
 *
 * @author Anastasiya
 *
 */

#include "arguments.h"
#include "util.h"
#include <string>
#include <cstdlib>

using namespace std;

Arguments* parseArgs(int argc, char* argv[]){
	Arguments* arguments = defaultArguments();

	for(int i = 1; i < argc; i++){
		string currentArg = string(argv[i]);
		if(isInput(currentArg)){
			i++;
			if(i < argc){
				arguments->inputPath = argv[i];
			}else{
				failure(MESSAGE_ARGUMENT_ERROR_INPUT_VALUE);
			}
		}else if(isOutput(currentArg)){
			i++;
			if(i < argc){
				arguments->outputPath = argv[i];
			}else{
				failure(MESSAGE_ARGUMENT_ERROR_OUTPUT_VALUE);
			}
		}else if(isReport(currentArg)){
			i++;
			if(i < argc){
				arguments->reportFileName = argv[i];
			}else{
				failure(MESSAGE_ARGUMENT_ERROR_REPORT_VALUE);
			}
		}else if(isTerse(currentArg)){
			arguments -> mode = MODE_TERSE;
		}else{
			failure(MESSAGE_ARGUMENT_ERROR_UNKNOWN_ARGUMENT + string(argv[i]));
		}
	}

	return arguments;
}

Arguments* defaultArguments(){
	Arguments* arguments = (Arguments*) malloc(sizeof(Arguments));

	arguments->mode = MODE_VERBOSE;
	arguments->inputPath = DIR_NAME_CURRENT.c_str();
	arguments->outputPath = DIR_NAME_CURRENT.c_str();

	return arguments;
}

bool isTerse(string arg){
	return arg.compare(ARGUMENT_NAME_TERSE) == 0;
}
bool isInput(string arg){
	return arg.compare(ARGUMENT_NAME_INPUT) == 0;
}
bool isOutput(string arg){
	return arg.compare(ARGUMENT_NAME_OUTPUT) == 0;
}
bool isReport(string arg){
	return arg.compare(ARGUMENT_NAME_REPORT) == 0;
}
